﻿using EkStudio.com.bean.xml.BillChart;
using EkStudio.Com.UI.Interface;
using ScintillaNET;
using System.Drawing;

namespace EkStudio.com.ui.form
{
    public partial class ChartDataSourceForm : DevExpress.XtraEditors.XtraForm
    {

        private BillChartModuleItem bean = null;
        private ProjectRootPanel RootPanel = null;
        private ProjectUnitBillInterface RootUnit = null;

        public ChartDataSourceForm(BillChartModuleItem _module, ProjectRootPanel root, ProjectUnitBillInterface unit)
        {
            InitializeComponent();
            bean = _module;
            RootPanel = root;
            RootUnit = unit;
            InitForm();
        }

        private void InitForm()
        {
            #region 初始化编辑器
            this.SqlEdit.Margins[0].Width = 20;
            this.SqlEdit.Margins[2].Type = MarginType.Symbol;
            this.SqlEdit.Margins[2].Mask = Marker.MaskFolders;
            this.SqlEdit.Margins[2].Sensitive = true;
            this.SqlEdit.Margins[2].Width = 20;

            SqlEdit.Markers[Marker.Folder].Symbol = MarkerSymbol.BoxPlus;
            SqlEdit.Markers[Marker.FolderOpen].Symbol = MarkerSymbol.BoxMinus;
            SqlEdit.Markers[Marker.FolderEnd].Symbol = MarkerSymbol.BoxPlusConnected;
            SqlEdit.Markers[Marker.FolderMidTail].Symbol = MarkerSymbol.TCorner;
            SqlEdit.Markers[Marker.FolderOpenMid].Symbol = MarkerSymbol.BoxMinusConnected;
            SqlEdit.Markers[Marker.FolderSub].Symbol = MarkerSymbol.VLine;
            SqlEdit.Markers[Marker.FolderTail].Symbol = MarkerSymbol.LCorner;

            SqlEdit.StyleResetDefault();
            SqlEdit.Styles[Style.Default].Font = "Consolas";
            SqlEdit.Styles[Style.Default].Size = 10;
            SqlEdit.StyleClearAll();


            // Configure the CPP (C#) lexer styles
            SqlEdit.Styles[Style.Cpp.Default].ForeColor = Color.Silver;
            SqlEdit.Styles[Style.Cpp.Comment].ForeColor = Color.FromArgb(0, 128, 0); // Green
            SqlEdit.Styles[Style.Cpp.CommentLine].ForeColor = Color.FromArgb(0, 128, 0); // Green
            SqlEdit.Styles[Style.Cpp.CommentLineDoc].ForeColor = Color.FromArgb(128, 128, 128); // Gray
            SqlEdit.Styles[Style.Cpp.Number].ForeColor = Color.Olive;
            SqlEdit.Styles[Style.Cpp.Word].ForeColor = Color.Blue;
            SqlEdit.Styles[Style.Cpp.Word2].ForeColor = Color.Blue;
            SqlEdit.Styles[Style.Cpp.String].ForeColor = Color.FromArgb(163, 21, 21); // Red
            SqlEdit.Styles[Style.Cpp.Character].ForeColor = Color.FromArgb(163, 21, 21); // Red
            SqlEdit.Styles[Style.Cpp.Verbatim].ForeColor = Color.FromArgb(163, 21, 21); // Red
            SqlEdit.Styles[Style.Cpp.StringEol].BackColor = Color.Pink;
            SqlEdit.Styles[Style.Cpp.Operator].ForeColor = Color.Purple;
            SqlEdit.Styles[Style.Cpp.Preprocessor].ForeColor = Color.Maroon;
            SqlEdit.Lexer = Lexer.Cpp;

            // Set the keywords
            //SqlEdit.SetKeywords(0, "abstract as base break case catch checked continue default delegate do else event explicit extern false finally fixed for foreach goto if implicit in interface internal is lock namespace new null object operator out override params private protected public readonly ref return sealed sizeof stackalloc switch this throw true try typeof unchecked unsafe using virtual while");
            //SqlEdit.SetKeywords(1, "bool byte char class const decimal double enum float int long sbyte short static string struct uint ulong ushort void");

            SqlEdit.SetKeywords(0, common.unit.ULabel.SQLKeys);

            #endregion


            SqlEdit.Text = bean.ChartProperties.Advanced.Content;

            if (RootUnit.ReadOnly) BtnSubmit.Enabled = false;
        }

        private void BtnSubmit_Click(object sender, System.EventArgs e)
        {
            if (RootUnit.ReadOnly) return;
            bean.ChartProperties.Advanced.Content = SqlEdit.Text;
            RootUnit.SaveStatus = false;
        }
    }
}